@extends('layouts.admin.application')

@section('content')
    <div class="main-content">
        <div class="col-xs-12">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                    <li>商品回收站</li>
                </ul>
            </div>

            @include('layouts.partials._flash')

            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">
                        <div class="col-sm-2">
                            <div id="sample-table-2_length" class="dataTables_length">
                                <a href="javascript:void(0);"
                                   class="btn btn-sm btn-primary" id="restore_checked">还原</a>
                                <a href="javascript:void(0);" class="btn btn-sm btn-purple" id="force_destroy_checked">彻底删除</a>
                            </div>
                        </div>
                    </div>
                    <table id="sample-table-2"
                           class="table table-striped table-bordered table-hover dataTable del-table"
                           aria-describedby="sample-table-2_info">
                        <thead>
                        <tr role="row">
                            <th class="center sorting_disabled" role="columnheader" rowspan="1" colspan="1"
                                aria-label="">
                                <label>
                                    <input type="checkbox" class="ace" id="check_all">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>商品名称</th>
                            <th>缩略图</th>
                            <th>所属分类</th>
                            <th>所属品牌</th>
                            <th>单价</th>
                            <th>上架日期</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        @foreach($goods as $good)
                            <tr class="odd" data-id="{{$good->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace checked_id" name="checked_id[]"
                                               value="{{$good->id}}">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{$good->id}}</td>
                                <td>{{$good->name}}</td>
                                <td><img src="{{$good->image}}" style="width: 40px;height: 35px;"></td>
                                <td>{{ $good->tags->implode('name', ', ') }}</td>
                                <td>{{$good->mark['name']}}</td>
                                <td>{{$good->price}}元</td>
                                <td>{{$good->created_at}}</td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="green" href="{{route('shop.good.restore', $good->id)}}"><i
                                                    class="icon-share bigger-120"></i></a>
                                        <a class="red" href="{{route('shop.good.force_destroy', $good->id)}}"
                                           data-method="delete" data-token="{{csrf_token()}}"
                                           data-confirm="确定要删除此条记录么?">
                                            <i class="icon-trash bigger-130"></i></a>
                                    </div>
                                </td>
                            </tr>
                        @endforeach

                        </tbody>
                    </table>
                    <div class="row">
                        <div class="col-sm-6">共 {{$goods->total()}} 条记录</div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_bootstrap">
                                <ul class="pagination">
                                    {{ $goods->appends(Request::all())->links() }}
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $(function () {
            //全选，反选
            $("#check_all").click(function () {
                $(':checkbox').prop("checked", this.checked);
            });

            //彻底删除多条
            $('#force_destroy_checked').click(function () {
                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

                var checked_id = $(".checked_id:checked").serialize();
                $.ajax({
                    type: "DELETE",
                    url: "{{route('shop.good.force_destroy_checked')}}",
                    data: checked_id,
                    success: function () {
                        window.location.reload();
                    }
                });
            });

            //还原多条
            $('#restore_checked').click(function () {
                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

                var checked_id = $(".checked_id:checked").serialize();

                $.ajax({
                    type: "POST",
                    url: "{{route('shop.good.restore_checked')}}",
                    data: checked_id,
                    success: function () {
                        window.location.reload();
                    }
                });
            });
        });
    </script>
@endsection


